/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sadhar.sipp.satuan;

import org.sadhar.sia.framework.ClassApplicationModule;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author hendro
 */
public class SatuanBarangPopupWnd extends ClassApplicationModule{
    private Textbox txtboxKeySearch;
    private Listbox lstboxSatuanBarang;
    private SatuanDAO satuanDAO;

    public SatuanBarangPopupWnd(){
        satuanDAO = new SatuanDAOImpl();
    }

    public void onCreate()throws Exception{
        txtboxKeySearch = (Textbox)getFellow("txtboxKeySearch");
        lstboxSatuanBarang = (Listbox)getFellow("lstboxSatuanBarang");
        load();
    }

    public void load()throws Exception{
        lstboxSatuanBarang.getItems().clear();
        int no = 1;
        for(Satuan satuan : satuanDAO.list(txtboxKeySearch.getValue().toString())){
            Listitem item = new Listitem();
            item.setValue(satuan);
            item.appendChild(new Listcell(""+ no++));
            item.appendChild(new Listcell(satuan.getSatuan().toString()));
            lstboxSatuanBarang.appendChild(item);
        }
    }

    public void lstboxSatuanBarangOnSelect()throws Exception{
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        Textbox txtboxCariSatuanBarang = (Textbox)window.getFellow("txtboxCariSatuanBarang");
        Textbox txtboxKodeSatuanBarang = (Textbox)window.getFellow("txtboxKodeSatuanBarang");
        Satuan satuan = (Satuan)lstboxSatuanBarang.getSelectedItem().getValue();
        txtboxCariSatuanBarang.setValue(satuan.getSatuan());
        txtboxKodeSatuanBarang.setValue(satuan.getKodeSatuanBarang()+"");
        this.detach();
    }
}
